package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.*;
import com.g8.pethospitallearnbackend.service.ExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/exam")
public class ExamController {
    @Autowired
    ExamService examService;

    @GetMapping
    public List<Exam> getAllExam(){
        List<Exam> list = examService.getAllExam();
        return list;
    }

    @RequestMapping("/{examId}")
    public Exam getExamById(@PathVariable("examId") String examId){
        Exam exam = examService.getExamById(examId);
        return exam;
    }

    @RequestMapping("/searchexam")
    public List<Exam> searchPaper(@RequestParam String searchExam){
        List<Exam> exams = examService.searchExam(searchExam);
        return exams;
    }

    @PostMapping
    public Exam addExam(@RequestBody Exam exam){
        return examService.addExam(exam);
    }

    @PutMapping
    public Exam change(@RequestBody Exam exam){
        return examService.changeExam(exam);
    }

    @DeleteMapping("/{examId}")
    public void deleteExam(@PathVariable("examId") String examId){
        examService.deleteExam(examId);
    }

    @RequestMapping("/userexam1")
    public List<Exam> userexam1(@RequestParam String userId){
        List<Exam> exams = examService.userExam1(userId);
        return exams;
    }

    @RequestMapping("/userexam0")
    public List<Exam> userexam0(@RequestParam String userId){
        List<Exam> exams = examService.userExam0(userId);
        return exams;
    }

    @PostMapping("/userexam")
    public List<ExamStuQues> submitExam(@RequestBody ExamStuSubmit examStuSubmit){
        List<ExamStuQues> examStuQuesList = examService.submitExam(examStuSubmit);
        return examStuQuesList;
    }

    @RequestMapping("/userpaper")
    public UsersExam usersExam(@RequestParam String userId, String examId){
        return examService.userExam(userId,examId);
    }

}
